package com.service.atm;

import com.bpms.InitServlet;
import com.bpms.common.Base64;
import com.bpms.common.CommonUtil;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.eai.PackTool;
import com.bpms.esb.IService;
import com.bpms.esb.SV;
import com.bpms.report.CommonGenReport;

public class Build_hdprintlist extends PackTool implements IService {

	public VO exec(VO args) {
		
		CommonUtil.debug("ATM.Build_hdprintlist init");
		VO vo=new VO();	
		try{
			StringBuffer buf=new StringBuffer();
			
			fieldpack(buf, "R001", "0000");
			fieldpack(buf, "R002", "打印成功");
			fieldpack(buf, "R003",  args.getAttr("cHostCod"));
			fieldpack(buf, "R004",  args.getAttr("iReqTrace"));
			fieldpack(buf, "R005",  args.getAttr("cRspId"));
			fieldpack(buf, "R006",  args.getAttr("iRspTrace"));
			fieldpack(buf, "R007",  args.getAttr("dRspDt"));
			fieldpack(buf, "R008",  args.getAttr("tReqTm"));
			fieldpack(buf, "R009",  args.getAttr("dAccDt"));
			fieldpack(buf, "R010",  args.getAttr("cRspCod"));
			fieldpack(buf, "R011", 	"01");
			
			VO report=new VO();
			report.setAttr("reportid", "report.Hdprintreport");
			VOList vol=new VOList();
			VO param = new VO();
			param=args;
			vol.listData.add(param);
			report.setObj("volist", vol);
			VO v = SV.g("report.Generatereport", report);
			CommonGenReport cgr=new CommonGenReport();
			byte[] bytes = null;
			VO p=new VO();
			p.setAttr("path", InitServlet.RealPath+"/report/bankReport.jasper");
			bytes = cgr.genPdfReport(p, v,InitServlet.RealPath);
			String pdfstr=Base64.encodeBytes(bytes);
			fieldpack(buf, "R012", 	pdfstr);
			
			StringBuffer msg=new StringBuffer();
			String body=buf.toString();
			String transcode="2002";
			String answer="0000";
			String wholeLen=addleft0(String.valueOf(body.getBytes().length), 8);
			//本报文长度（不包括自身长度）+流水号+整个交易报文长度
			String instanceid="00000000";
			int bodylen=body.getBytes().length+instanceid.getBytes().length+
			wholeLen.getBytes().length+transcode.getBytes().length+
						answer.getBytes().length;
			
			String strLen=addleft0(String.valueOf(bodylen), 8);
			msg.append(strLen);
			msg.append(instanceid);
			msg.append(wholeLen);
			msg.append(transcode);
			msg.append(answer);
			msg.append(body);
			vo.setAttr("msg", msg.toString());
			CommonUtil.debug("ATM.Build_hdprintlist vo:"+vo.toString());
			return vo;
		}
		catch(Exception e)
		{
			CommonUtil.debug("ATM.Build_hdprintlist exception",e);
			StringBuffer msg=new StringBuffer();
			StringBuffer buf=new StringBuffer();
			fieldpack(buf, "R001", "1111");//处理结果代码
			fieldpack(buf, "R002", "生成回执报文出错");//结果描述
			String body=buf.toString();
			String instanceid="00000000";
			String transcode="2002";
			String answer="1111";
			String wholeLen=addleft0(String.valueOf(body.getBytes().length), 8);
			//本报文长度（不包括自身长度）+流水号+整个交易报文长度
			int bodylen=body.getBytes().length+instanceid.getBytes().length+
			wholeLen.getBytes().length+transcode.getBytes().length+
						answer.getBytes().length;
			String strLen=addleft0(String.valueOf(bodylen), 8);
			instanceid=addleft0(instanceid, 8);
			msg.append(strLen);
			msg.append(instanceid);
			msg.append(wholeLen);
			msg.append(transcode);
			msg.append(answer);
			msg.append(body);
			vo.setAttr("msg", msg.toString());
			return vo;
		}
	}


}
